package com.huanuo.internetofthings.service.resources;

import com.huanuo.internetofthings.bo.roleResources.RoleResources;
import com.huanuo.internetofthings.dao.roleResources.RoleResourcesMapper;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.unicorn.framework.base.base.AbstractService;
import org.unicorn.framework.core.SysCode;
import org.unicorn.framework.core.exception.PendingException;

@Service
public class RoleResourcesService extends AbstractService {

	@Autowired
	private RoleResourcesMapper roleResourcesMapper;

	public List<RoleResources> getRoleResourceListByRoleIds(List<Integer> roleIds) throws PendingException {
		try {
			if (CollectionUtils.isEmpty(roleIds)) {
				return Lists.newArrayList();
			}
			return this.roleResourcesMapper.selectListByRoleIds(roleIds);
		} catch (Exception e) {
			error("查询角色拥有资源表失败",  e );
			throw new PendingException(SysCode.DB_ERROR, "查询角色拥有资源表失败");
		}
		
	}

	public List<RoleResources> getRoleResourceList(RoleResources roleResources) throws PendingException {
		try {
			return this.roleResourcesMapper.selectList(roleResources);
		} catch (Exception e) {
			error("查询角色拥有资源表失败", e);
			throw new PendingException(SysCode.DB_ERROR, "查询角色拥有资源表失败");
		}
		
	}
}